package com.erastep.base;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import flex.messaging.FlexContext;

/**
 * @author Jarvis
 * 用于管理 Session
 * */
public class SessionManager {
	private static SessionManager instance = null;
	
	 protected SessionManager() {   
	      // Exists only to defeat instantiation.   
	 }   
     public static SessionManager getInstance() {   
    	 if(instance == null) {   
    		 instance = new SessionManager();   
    	 }   
    	 return instance;   
     } 
     
     /**
      * 获取用户的Session
      * @param atr Session Key
      * */
     public Object getSession(String atr){
         HttpSession session = getSession();
         return session.getAttribute(atr);
     }
     public HttpServletRequest getRequest(){
    	 HttpServletRequest request = FlexContext.getHttpRequest();
    	 return request;
     }
     public HttpSession getSession(){
    	 return getRequest().getSession();
     }
     public HttpServletResponse getResponse(){
         return FlexContext.getHttpResponse();    	 
     }
     /**
      * 获得系统路径
      * */
     public String getRealPath(){
         return getRequest().getSession().getServletContext().getRealPath("/"); 
     }
}
